<template>
	<!-- <img src="/static/bg.png" alt="" class="bg"/> -->
	<div class=" w-screen flex justify-center ">
		<view class="box ">
			<Meslist></Meslist>
		</view>
	</div>
</template>

<script>
	import Meslist from "@/modul/Home/messagelist.vue"
	import {
		getMypost,
		getchatHistroyUser,
		getothermessage
	} from '@/store/api.js'
	export default {
		onShow() {
			if (uni.getStorageSync('a_tk')) {
				setTimeout(() => {
					uni.getClipboardData({
						success: (res) => {
							console.log('获取剪贴板');
							console.log(res.data);
							if (res.data.startsWith('复制到Meet打开：快来加入我们吧:')) {
								console.log('对上了');
								console.log(res.data.split('复制到Meet打开：快来加入我们吧:'));
								uni.navigateTo({
									url: `/subpkg/mes_detail/mes_detail?id=${res.data.split('复制到Meet打开：快来加入我们吧:')[1]}`,
									complete: () => {
										console.log('跳转完成，移除剪贴板第一条内容');
										this.removeFirstClipboard();
									}
								});
							}
						},
						fail: (err) => {
							console.log(err);
						}
					});
				}, 1000)

			}
		},


		onLoad() {
			uni.setStorageSync('AlreadyConnect', false)

			if (!uni.getStorageSync('chat_History_page')) {
				let chatPage = []
				getchatHistroyUser().then(res => {
					console.log('聊天对象')
					console.log(res)
					res.data.data.forEach(item => {
						if (chatPage.find(it => item.userid == it.userid)) {} else {
							chatPage.unshift({
								name: item.userName,
								src: item.avatar,
								userid: item.id,
								content: '',
								time: '',
								new: false
							})
						}
					})
					uni.setStorageSync('chat_History_page', chatPage)
					// },2000)

					// setTimeout(() => {
					// 	uni.connectSocket({
					// 		url: `wss://meet.ysyxmy.top/web/socket?access_token=${token}`,
					// 	});
					// },1000)
				})
			} else {
				if (uni.getStorageSync('detail')) {
					let id = uni.getStorageSync('detail')
					uni.removeStorageSync('detail')
					uni.navigateTo({
						url: `/subpkg/mes_detail/mes_detail?id=${uni.getStorageSync('id')}`
					})
				}

			}
		},
		components: {
			Meslist,
		},
		data() {
			return {

			};
		},
		methods: {
			removeFirstClipboard() {
				uni.getClipboardData({
					success: (res) => {
						uni.showToast({
							duration: 100,
							title: '获取成功',
							icon: 'success'
						})
						let clipboardData = res.data.split("\n");
						clipboardData.shift(); // 删除第一条内容
						let newData = clipboardData.join("\n");

						uni.setClipboardData({
							data: newData,
							success: () => {
								console.log("剪贴板第一条内容删除成功");
							},
							fail: (err) => {
								console.log("剪贴板第一条内容删除失败: " + JSON.stringify(err));
							}
						});
					},
					fail: (err) => {
						console.log("获取剪贴板内容失败: " + JSON.stringify(err));
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 100vw;
		padding-top: 50px;
		background-color: rgba(243, 243, 243, 0.934);
	}

	@media screen and (min-width: 600px) {
		.box {
			width: 35vw;
			padding-top: 50px;
			background-color: rgba(243, 243, 243, 0.934);
			padding-bottom: 50px;

		}
	}
</style>